﻿
using System.Web.Mvc;
using Kaiser.InversionOfControl;
using Kaiser.Models;
using Kaiser.Modules.CMS.Services;
using Kaiser.Modules.Cubic.DomainModel.Board;
using Kaiser.Modules.Cubic.Repositories;
using Kaiser.Modules.Cubic.Services;
using Kaiser.Modules.Cubic.Services.Impl;
using Kaiser.Modules.Cubic.ViewModel;
using Kaiser.Repositories.iBatis;
using Kaiser.Repositories.iBatis.CUBIC;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaiser.Modules.Cubic.DomainModel.Product;

namespace Kaiser.Modules.Test
{
    /// <summary>
    ///这是 CubicTest 的测试类，旨在
    ///包含所有 CubicTest 单元测试
    ///</summary>
    [TestClass()]
  
    [DeploymentItem(@"Kaiser.Site\Maps", "Maps")]
    [DeploymentItem(@"Kaiser.Site\Configs", "Configs")]
    public class CubicTest
    {
        public CubicTest()
        {
            DependencyResolver.SetResolver(new DependencyResolverFactory().CreateDependencyResolver());
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        public ProductRepositorie ProductRepositorieObject
        {
            get
            {
                return new ProductRepositorie();

            }
        }

        public IProductRepositorie ProductRepositorie
        {
            get
            {
                return new ProductRepositorie();
            }
        }


        public IProductCategoryRepositorie ProductCategoryRepositorie
        {
            get
            {
                return new ProductCategoryRepositorie();
            }
        }

        /// <summary>
        ///GetProductTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetProductTest()
        {
            try
            {
                CubicService target = new CubicService(); //  
                string primaryId = "0584b6df-1676-4a9d-bee2-a20e01746948"; // 
                target.GetProduct(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///GetProductsByCategoryCodeTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetProductsByCategoryCodeTest()
        {
            try
            {
                CubicService target = new CubicService(ProductRepositorie);
                string primaryId = "30";
                target.GetProductsByCategoryCode(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///GetProductCateogrysTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetProductCateogrysTest()
        {
            try
            {
                CubicService target = new CubicService(ProductRepositorie);
                string primaryId = "2";
                target.GetProductCateogrys(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///GetProductCategoryTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetProductCategoryTest()
        {
            try
            {
                CubicService target = new CubicService(ProductRepositorie);
                string primaryId = "7";
                target.GetProductCategory(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///GetNewsByCategoryCodeTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetNewsByCategoryCodeTest()
        {
            try
            {
                CubicService target = new CubicService(ProductRepositorie);
                string primaryId = "2";
                target.GetNewsByCategoryId(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///AddMessageTest 的测试
        ///</summary>
        [TestMethod()]
        public void AddMessageTest()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    CubicService target = new CubicService(ProductRepositorie);
                    var model = new Message();
                    model.MessageId = Guid.NewGuid().ToString();
                    model.Content = "Test0001" + i.ToString();
                    model.Email = "123@123.com";
                    model.Company = "0000111";
                    model.MsnSky = "13123";
                    model.ProductName = "名称";
                    model.TelFax = "username";

                    target.AddMessage(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        /// <summary>
        ///GetNewsTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetNewsTest()
        {
            try
            {
                CubicService target = new CubicService(ProductRepositorie);
                string primaryId = "10132";
                target.GetNews(primaryId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        [TestMethod()]
        public void GetCubicProductCategoryTest()
        {
            try
            {
                CubicService target = new CubicService();
                string primaryId = "10132";
                var resul=target.GetProductCateogrys(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///GetNewsTest 的测试
        ///</summary>
        [TestMethod()]
        public void GetCategoryTreeList()
        {
            try
            {
                IProductCategoryService target = new ProductCategoryService(ProductCategoryRepositorie);
                target.GetCategoryTreeList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        /// AddCategory 的测试
        /// </summary>
        [TestMethod()]
        public void AddCategory()
        {
            try
            {
                ProductCategoryService target = new ProductCategoryService(ProductCategoryRepositorie);
                var model = new ProductCategory();
                model.CategoryName = "test2";
                model.CategoryCode = "test2";
                model.Sequence = 1;
                model.CategoryImg = "fsdf";
                model.CategoryUrl = "asdf";
                model.ContentCount = 1;
                model.CategoryDesc = "fsadf";
                model.SeoTitle = "asdf";
                model.SeoH1 = "asdf";
                model.SeoDes = "sdf";
               
                model.CreateMan = "admin";
                model.CreateTime = DateTime.Now;
                target.Insert(model);
            }
            catch (Exception)
            {

                throw;
            }
            Assert.IsFalse(false);
        }

        /// <summary>
        /// EditCategory 的测试
        /// </summary>
        [TestMethod()]
        public void EditCategory()
        {
            try
            {
                ProductCategoryService target = new ProductCategoryService(ProductCategoryRepositorie);
                var model = new ProductCategory();
                model.Id = 12;
                model.CategoryName = "test2";
                model.CategoryCode = "test2";
                model.Sequence = 1;
                model.CategoryImg = "fsdf";
                model.CategoryUrl = "asdf";
                model.ContentCount = 1;
                model.CategoryDesc = "fsadf";
                model.SeoTitle = "asdf";
                model.SeoH1 = "asdf";
                model.SeoDes = "sdf";
                model.ParentId =0;
                model.CreateMan = "admin";
                model.CreateTime = DateTime.Now;
                target.Update(model);
            }
            catch (Exception)
            {

                throw;
            }
            Assert.IsFalse(false);
        }

        /// <summary>
        /// DelCategory 的测试
        /// </summary>
        [TestMethod()]
        public void DelCategory()
        {
            try
            {
                ProductCategoryService target = new ProductCategoryService(ProductCategoryRepositorie);

                var model = new ProductCategory();
                model.Id = 11;
                target.Delete(model);
            }
            catch (Exception)
            {
                throw;
            }
            Assert.IsFalse(false);
        }


        /// <summary>
        /// DelCategory 的测试
        /// </summary>
        [TestMethod()]
        public void SearchAdvert()
        {
            try
            {
 
                // 设置 IoC/DI 容器。用于替换ASP.NET MVC内置的依赖注入容器DefaultDependencyResolver
                DependencyResolver.SetResolver(new DependencyResolverFactory().CreateDependencyResolver());
                var target = new AdvertService();

                target.Search(new AdvertSearch(), new PagingInfo(0, 10));

               
            }
            catch (Exception)
            {
                throw;
            }
            Assert.IsFalse(false);
        }

        [TestMethod()]
        public void GetAdvertSpaceByCode()
        {
            try
            {
 
                // 设置 IoC/DI 容器。用于替换ASP.NET MVC内置的依赖注入容器DefaultDependencyResolver
             
                var target = new CubicService();

                var model=target.GetAdvertSpaceByCode("HomeBanner");

                Assert.IsTrue(model!=null);
                Assert.IsTrue(model.AdvertDetail.Count>0);
            }
            catch (Exception)
            {
                throw;
            }
            Assert.IsFalse(false);
        }

        [TestMethod()]
        public void GetNewsCategorysByParentCode()
        {
            try
            {

                // 设置 IoC/DI 容器。用于替换ASP.NET MVC内置的依赖注入容器DefaultDependencyResolver

                var target = new CubicService();

                var model = target.GetNewsCategorysByParentCode("AboutCubic_English");

                Assert.IsTrue(model != null);
                Assert.IsTrue(model.Count > 0);
                Assert.IsTrue(model[0].children.Count > 0);
            }
            catch (Exception)
            {
                throw;
            }
            Assert.IsFalse(false);
        }
    }
}
